#include <blt/namer.h>
#include <blt/syscall.h>
#include <blt/conio.h>
#include <blt/os.h>
#include <blt/qsem.h>
#include <string.h>
#include "Renderer_vga.h"
#include "GraphicsContext.h"
#include "Window.h"
#include "WindowManager.h"
#include "vga.h"


struct ColorMapEntry {
	int red;
	int green;
	int blue;
} colorTable[255] = {
	{0, 0, 0},
	{112, 219, 147},
	{112, 219, 147},
	{50, 204, 153},
	{50, 204, 153},
	{0, 0, 0},
	{0, 0, 0},
	{0, 0, 255},
	{0, 0, 255},
	{95, 159, 159},
	{95, 159, 159},
	{66, 66, 111},
	{66, 66, 111},
	{107, 35, 142},
	{107, 35, 142},
	{191, 216, 216},
	{191, 216, 216},
	{143, 143, 188},
	{143, 143, 188},
	{50, 50, 204},
	{50, 50, 204},
	{127, 0, 255},
	{127, 0, 255},
	{47, 47, 79},
	{47, 47, 79},
	{35, 35, 142},
	{35, 35, 142},
	{35, 35, 142},
	{35, 35, 142},
	{50, 153, 204},
	{50, 153, 204},
	{0, 127, 255},
	{0, 127, 255},
	{35, 107, 142},
	{35, 107, 142},
	{255, 127, 0},
	{255, 127, 0},
	{0, 255, 255},
	{0, 255, 255},
	{142, 35, 35},
	{142, 35, 35},
	{204, 127, 50},
	{204, 127, 50},
	{219, 219, 112},
	{219, 219, 112},
	{234, 234, 173},
	{234, 234, 173},
	{0, 255, 0},
	{0, 255, 0},
	{47, 79, 47},
	{47, 79, 47},
	{79, 79, 47},
	{79, 79, 47},
	{35, 142, 35},
	{35, 142, 35},
	{50, 204, 50},
	{50, 204, 50},
	{107, 142, 35},
	{107, 142, 35},
	{66, 111, 66},
	{66, 111, 66},
	{127, 255, 0},
	{127, 255, 0},
	{143, 188, 143},
	{143, 188, 143},
	{35, 142, 107},
	{35, 142, 107},
	{0, 255, 127},
	{0, 255, 127},
	{153, 204, 50},
	{153, 204, 50},
	{47, 79, 79},
	{47, 79, 79},
	{47, 79, 79},
	{47, 79, 79},
	{84, 84, 84},
	{84, 84, 84},
	{84, 84, 84},
	{84, 84, 84},
	{168, 168, 168},
	{168, 168, 168},
	{168, 168, 168},
	{168, 168, 168},
	{159, 159, 95},
	{159, 159, 95},
	{255, 0, 255},
	{255, 0, 255},
	{142, 35, 107},
	{142, 35, 107},
	{204, 50, 50},
	{204, 50, 50},
	{219, 112, 219},
	{219, 112, 219},
	{153, 50, 204},
	{153, 50, 204},
	{147, 112, 219},
	{147, 112, 219},
	{188, 143, 143},
	{188, 143, 143},
	{234, 173, 234},
	{234, 173, 234},
	{255, 0, 0},
	{255, 0, 0},
	{79, 47, 47},
	{79, 47, 47},
	{219, 112, 147},
	{219, 112, 147},
	{255, 0, 127},
	{255, 0, 127},
	{204, 50, 153},
	{204, 50, 153},
	{111, 66, 66},
	{111, 66, 66},
	{142, 107, 35},
	{142, 107, 35},
	{219, 147, 112},
	{219, 147, 112},
	{216, 191, 216},
	{216, 191, 216},
	{173, 234, 234},
	{173, 234, 234},
	{112, 147, 219},
	{112, 147, 219},
	{112, 219, 219},
	{112, 219, 219},
	{79, 47, 79},
	{79, 47, 79},
	{159, 95, 159},
	{159, 95, 159},
	{216, 216, 191},
	{216, 216, 191},
	{252, 252, 252},
	{252, 252, 252},
	{255, 255, 0},
	{255, 255, 0},
	{147, 219, 112},
	{147, 219, 112},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255},
	{255, 255, 255}		// Transparent color
};


int main()
{
	InitVGA();
	char *vmem = (char*) 0xa0000;
	area_create(64*1024, 0, (void**) &vmem, AREA_PHYSMAP);
	memset((void*) vmem, 0, 320 * 200);
	
	Renderer *screen = new Renderer_vga((char*) vmem, 320, 200, 320);
	for (int i = 0; i < 256; i++)
		SetPalette(i, colorTable[i].red, colorTable[i].green, colorTable[i].blue);

	new WindowManager(screen);
	return 0;
}
